package testWork;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class test5{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Set<String> zhuSet = new HashSet<>();
        Set<String> weiSet = new HashSet<>();
        Set<String> binSet = new HashSet<>();
        int n1 = scanner.nextInt();
        int n2 = scanner.nextInt();
        int n3 = scanner.nextInt();
        for (int i = 0; i < n1; i++) {
            zhuSet.add(scanner.next());
        }
        for (int i = 0; i < n2; i++) {
            weiSet.add(scanner.next());
        }
        for (int i = 0; i < n3; i++) {
            binSet.add(scanner.next());
        }

        int m = scanner.nextInt();
        scanner.nextLine();//换行符
        for (int i = 0; i < m; i++) {
            String str = scanner.nextLine();
            String[] s = str.split(" ");
            int state = 0;
            int zhu = 0;
            boolean judge = true;
            for (int j = 0; j < s.length; j++) {
                if(j==0&&!zhuSet.contains(s[j])){
                    System.out.println("NO");
                    judge = false;
                    break;
                }
                if(state==0){
                    if(weiSet.contains(s[j])){
                        if(zhu>0){
                            state++;
                        }else{
                            System.out.println("NO");
                            judge = false;
                            break;
                        }
                    }else if(zhuSet.contains(s[j])){
                        zhu++;
                    }else{
                        System.out.println("NO");
                        judge = false;
                        break;
                    }
                }else if(state==1){
                    if(binSet.contains(s[j])){

                    }else{
                        System.out.println("NO");
                        judge = false;
                        break;
                    }
                }
            }
            if(judge){
                System.out.println("YES");
            }
        }

    }
}


